package com.fy.shardingsphere.controller;

import com.fy.shardingsphere.dto.OrderCreateRequest;
import com.fy.shardingsphere.entity.Order;
import com.fy.shardingsphere.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.atomic.AtomicLong;

@Api(tags = "订单管理")
@RestController
@RequestMapping("/api/orders")
public class OrderController {
    
    private final OrderService orderService;
    private final AtomicLong orderIdGenerator = new AtomicLong(1);

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    @ApiOperation("创建订单")
    @PostMapping
    public void createOrder(@RequestBody OrderCreateRequest request) {
        Order order = new Order();
        BeanUtils.copyProperties(request, order);
        // 生成订单ID
        order.setOrderId(orderIdGenerator.getAndIncrement());
        orderService.createOrder(order);
    }
} 